from app import create_app
import sys

application = create_app(flask_config='testing')
from app.extensions import db
from app.modules.user.models import User

reload(sys)
sys.setdefaultencoding('utf8')

def create_db():
    with application.app_context():
        db.create_all()

def drop_all():
    with application.app_context():
        db.drop_all()

def query():
    with application.app_context():
        _app_list = User.query.all()
        # _apps = User.query.filter_by(on_beetle = 'true').group_by(App.app_name)
        for us in _app_list:
            print us

        # _app_list = User.query.filter_by(user_shuxue = 11).all()
        # for us in _app_list:
        #     print us


def update():
    with application.app_context():
        _app_list = User.query.all()
        for us in _app_list:
            us.user_name="aaaa"
        db.session.commit()


def insert():
    with application.app_context():
        us1 = User("1","1@",11,11,11)
        us2 = User("2","2@",22,22,22)
        us3 = User("3","3@",33,33,33)
        us4 = User("4","4@",44,44,44)
        db.session.add(us1)
        db.session.add(us2)
        db.session.add(us3)
        db.session.add(us4)
        db.session.commit()


# create_db()
drop_all()
# query()
# insert()
# update()